package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;

/**
 * @author stone
 * @date 2021/11/24 11:25
 */
@RestController
@RequestMapping("user")
public class UserController {

    //localhost:8080/user/register?username=songge&password=niupi&age=30&birthday=1991/11/24
    @RequestMapping("register")
    public BaseRespVo register(String username, String password, Integer age, Date birthday) {
        if (username == null || username.length() < 6) {
            return BaseRespVo.fail("用户名过短");
        }
        if (password == null || password.length() < 6) {
            return BaseRespVo.fail("密码太短了");
        }
        if (age == null || age < 18) {
            return BaseRespVo.fail("防沉迷");
        }
        if (birthday.compareTo(new Date()) > 0) {
            return BaseRespVo.fail("你不能在将来的某一天出生");
        }
        return BaseRespVo.ok(null);
    }

    //localhost:8080/user/register?username=songge&password=niupi&age=30&birthday=1991/11/24
    @RequestMapping("register2")
    public BaseRespVo register2(@Valid User user) {

        return BaseRespVo.ok(null);
    }

}
